class Solution {
public:

    void dfs(vector<int>& x, vector<int>& y, vector<int>& z, int num)
    {
        if (num == 1)
        {
            z.push_back(x.back());
            x.pop_back();
            return;
        }

        dfs(x, z, y, num - 1);
        z.push_back(x.back());
        x.pop_back();
        dfs(y, x, z, num - 1);
    }

    void hanota(vector<int>& A, vector<int>& B, vector<int>& C) {
        int n = A.size();
        dfs(A, B, C, n);
    }
};